﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using PassBag;
using PassBag.Logic;

namespace TestPassBag {
    [TestFixture, Description ("Test contain method and Equality and Inequality for PasswordObject")]
    public class ContainEquality {

        [Test, Description ("The Contain method from generic list")]
        public void TestContainMethod () {
            List<PasswordObject> passwordList = new List<PasswordObject> ();
            PasswordObject password = new PasswordObject ();
            Guid guid = Guid.NewGuid ();

            password = new PasswordObject ();
            password.Id = Guid.NewGuid();
            passwordList.Add (password);

            password = new PasswordObject ();
            password.Id = guid;
            passwordList.Add (password);

            password = new PasswordObject ();
            password.Id = Guid.NewGuid ();
            passwordList.Add (password);

            password = new PasswordObject ();
            password.Id = Guid.NewGuid ();
            passwordList.Add (password);

            PasswordObject password2 = new PasswordObject ();
            password2.Id = guid;
            password2.UserName = "user";
            Assert.IsTrue (passwordList.Contains (password2));

            PasswordObject password3 = new PasswordObject ();
            password3.Id = Guid.NewGuid ();
            password3.UserName = "user";
            Assert.IsFalse (passwordList.Contains (password3));
        }

        [Test, Description ("The PasswordObject equality using == operator (IEquatable) on field Id")]
        public void Equality () {
            Guid guid = Guid.NewGuid ();
            PasswordObject password = new PasswordObject ();
            password.Id = guid;
            password.UserName = "User";

            PasswordObject password2 = new PasswordObject ();
            password2.Id = guid;
            password2.UserName = "User name";
            password2.Information = "The information";

            PasswordObject password3 = new PasswordObject ();
            password3.Id = Guid.NewGuid ();
            password3.UserName = "User name";
            password3.Information = "The information";

            Assert.IsTrue (password == password2);
            Assert.IsFalse (password == password3);
        }

        [Test, Description ("The PasswordObject inequality using != operator (IEquatable) on field Id")]
        public void Inequality () {
            Guid guid = Guid.NewGuid ();
            PasswordObject password = new PasswordObject ();
            password.Id = guid;
            password.UserName = "User";

            PasswordObject password2 = new PasswordObject ();
            password2.Id = guid;
            password2.UserName = "User name";
            password2.Information = "The information";

            PasswordObject password3 = new PasswordObject ();
            password3.Id = Guid.NewGuid ();
            password3.UserName = "User name";
            password3.Information = "The information";

            Assert.IsFalse (password != password2);
            Assert.IsTrue (password != password3);
        }
    }
}
